# make_big_csv.py
import csv, random, datetime, pathlib, hashlib

OUT = pathlib.Path('big_demo.csv')
ROWS = 10*10000
random.seed(42)

# 1. 准备池子，保证重复值
uids   = [f'U{random.randint(1, 20_000):06d}' for _ in range(20_000)]
cats   = ['A', 'B', 'C', 'D', 'E']
prods  = ['P' + hashlib.md5(str(i).encode()).hexdigest()[:6].upper()
          for i in range(500)]

with OUT.open('w', newline='', encoding='utf-8') as f:
    w = csv.writer(f)
    w.writerow(['user_id', 'order_date', 'category', 'product_id',
                'qty', 'price', 'discount', 'revenue', 'notes'])
    base_date = datetime.date(2020, 1, 1)
    combo_items = []
    for i in range(10):
        combo_items.append(str(i))
    for i in range(ROWS):
        uid  = random.choice(uids)
        dt   = base_date + datetime.timedelta(days=random.randint(0, 1825))
        cat  = random.choice(cats)
        prod = random.choice(prods)
        qty  = random.randint(1, 20)
        price = round(random.uniform(5, 999), 2)
        disc = round(random.uniform(0, 0.4), 2) if random.random() < 0.3 else 0
        rev  = round(qty * price * (1 - disc), 2)
        notes =  random.choice(combo_items)#random.choice(['', '', '', 'VIP', 'Gift', 'Return','RRRR'])  # 故意留空
        w.writerow([uid, dt, cat, prod, qty, price, disc, rev, notes])

print(OUT.resolve(), 'done', OUT.stat().st_size // 1024, 'KB')